from django.db import models
from util.typing import DjangoModelTyping


class Region(models.Model):
    id = models.BigAutoField(
        primary_key=True,
        unique=True,
        verbose_name='主键'
    )
    name = models.CharField(
        max_length=255,
        verbose_name='地区'
    )
    parent_region = models.ForeignKey(
        'common.Region',
        on_delete=models.CASCADE,
        null=True,
        verbose_name='父分类'
    )
    user = models.ForeignKey(
        'user.User',
        null=False,
        on_delete=models.CASCADE,
        verbose_name='由哪个用户创建'
    )

    class Meta(DjangoModelTyping):
        db_table = 'region'

        permissions = (
            ('region_post', '添加区域'),
            ('region_patch', '修改区域'),
            ('region_delete', '删除区域'),
            ('region_get', '查询区域'),
        )
        default_permissions = ()
